{extend name="public:base" /}
{block name="head"}
<link href="__PUBLIC__/view_res/mobile/css/login.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/css/jquery-weui.min.css" type="text/css" rel="Stylesheet" />
<script src="__PUBLIC__/jquery-weui/dist/js/jquery-weui.min.js"></script>
<link href="__PUBLIC__/view_res/mobile/css/uc.css" type="text/css" rel="Stylesheet" />
{/block} 
{block name="header"}
{include file="public/top-nav" /}
{/block}

{block name="content"}
<style>
	body {
		background : none;
	}
</style>
<div id="container">
	<div class="register">
	    <form class="am-form" method="post" action="" role="form">
	    <div class="weui_cells_title">用户注册</div>
	    <div class="weui_cells weui_cells_form">


	    	
	        <div class="weui_cell">
	            <div class="weui_cell_hd">
	                <label for="" class="weui_label">手机号</label>
	            </div>
	            <div class="weui_cell_bd weui_cell_primary">
	                <input name="username" id="mobile" class="weui_input" required="" placeholder="请输入您的手机号码" type="number">
	            </div>            
	        </div>

	        <div class="weui_cell">
	            <div class="weui_cell_hd">
	                <label for="" class="weui_label">您的昵称</label>
	            </div>
	            <div class="weui_cell_bd weui_cell_primary">
	                <input name="nickname" class="weui_input" required="" placeholder="请输入您的昵称" type="text" style="border:none">
	            </div>            
	        </div>
	   
	        <div class="weui_cell">
	            <div class="weui_cell_hd">
	                <label for="" class="weui_label">密码</label>
	            </div>
	            <div class="weui_cell_bd weui_cell_primary">
	                <input name="password" class="weui_input" required="" pattern="[\w]{6,}" notmatchtips="密码至少6位" placeholder="请输入密码" type="password">
	            </div>            
	        </div>
	        <div class="weui_cell">
	            <div class="weui_cell_hd">
	                <label for="" class="weui_label">密码确认</label>
	            </div>
	            <div class="weui_cell_bd weui_cell_primary">
	                <input name="pwd2" class="weui_input" required="" pattern="[\w]{6,}" notmatchtips="密码至少6位" placeholder="请再次输入密码" type="password">
	            </div>            
	        </div>

	        <div class="weui_cell">
	            <div class="weui_cell_hd">
	                <label for="" class="weui_label">二级密码</label>
	            </div>
	            <div class="weui_cell_bd weui_cell_primary">
	                <input name="2password" class="weui_input" required="" pattern="[\w]{6,}" notmatchtips="密码至少6位" placeholder="请输入密码" type="password">
	            </div>            
	        </div>
	        <div class="weui_cell">
	            <div class="weui_cell_hd">
	                <label for="" class="weui_label">二级密码确认</label>
	            </div>
	            <div class="weui_cell_bd weui_cell_primary">
	                <input name="2pwd2" class="weui_input" required="" pattern="[\w]{6,}" notmatchtips="密码至少6位" placeholder="请再次输入密码" type="password">
	            </div>            
	        </div>
	        {if condition="1 eq config('use_captcha')"}	
	        <div class="weui_cell weui_vcode">
			<div class="weui_cell_hd">
				<label class="weui_label">验证码</label>
			</div>
			<div class="weui_cell_bd weui_cell_primary">
				<input name="captcha" class="weui_input" type="text" placeholder="请输入验证码">
			</div>
			<div class="weui_cell_ft">
				<img class="verifyimg reloadverify" src="{:url('login/verify')}">
			</div>
			</div>
			{/if}

				        <div class="weui_cell">
	            <div class="weui_cell_hd">
	                <label for="" class="weui_label">推荐人</label>
	            </div>
	            <div class="weui_cell_bd weui_cell_primary">
	                <input name="sharemobile" class="weui_input" required="" placeholder="请输入推荐人手机号码" type="number" value="{:input('sharemobile')}">
	            </div>            
	        </div>
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<label for="" class="weui_label">短信验证码</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input name="code" class="weui_input" required="" placeholder="请输入您的短信验证码" type="number">
				</div>
				<div class="weui_cell_hd">
					<input type="button" id="btn" style="width: 110%; height: 25px; border: none;text-align: center;color:#fff; background: #e4383b;border-radius: 5px;" class="am-btn am-btn-danger" onclick="sendsms()" value="获取验证码" />
				</div>
			</div>
	    </div>

	    <div class="weui_btn_area">
	        <a class="weui_btn weui_btn_primary js_btn" style="background: #e4383b">注册</a>
	    </div>
	    <p class="weui_cells_tips"><a href="{:url('login/login')}">已有账号？<span class="go_login" style="color: #e4383b">去登录</span></a></p>
	</form>
		<p class="am-text-danger">{$error|default=''}</p>
	</div>
</div>
{/block}

{block name="footer"}

{/block}

{block name="script"}
<script>

<?php if(1==config('use_captcha')){ ?>
	//刷新验证码
	var verifyimg = $(".verifyimg").attr("src");
    $(".reloadverify").click(function(){
        if( verifyimg.indexOf('?')>0){
            $(".verifyimg").attr("src", verifyimg+'&random='+Math.random());
        }else{
            $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
        }
    });	
<?php } ?>

$('.js_btn').click(function(){
	$.post(
		"{:url('login/reg')}",
		$('input[type=\'number\'],input[type=\'text\'],input[type=\'password\']'),
		function(d){
			if(d.error){			
				$.toast(d.error,"forbidden");			
			}else if(d.success){				
				$.toast(d.success);				
				if(d.url){
					setTimeout(function (){
				        location.href=d.url;
				    }, 1000);					
				}				
			}
		}
	);	
});


var wait=60*2;
document.getElementById("btn").disabled = false;


//$.post("/passport/regsms",{mobile:encodeURIComponent($("#mobile").val())});
function time(o) {
    if (wait == 0) {
      o.removeAttribute("disabled");
      o.value="免费获取验证码";
      wait = 60;
    } else {
      o.setAttribute("disabled", true);
      o.value="重新发送(" + wait + ")";
      wait--;
      setTimeout(function() {
        time(o)
      },
      1000)
    }
  }

function sendsms(){

        var i=60;
		var wait=60;
                    //var phone=document.getElementById("mobile").val;
		var phone = $("#mobile").val();

		if(phone!="")
		{
			//alert('test');
		    //alert('已经发送验证码到您手机，请注意查收!');
		
			document.getElementById("btn").disabled = false;

			$.post("/mobile/login/regsms",{mobile:encodeURIComponent($("#mobile").val())},
						function(d){
						   //layer.msg(d.info);
								
							time(document.getElementById("btn"));

						});
		}

    }
</script>
{/block}